// 路径配置
require.config({
    paths: {
        echarts: '/static/common/js/incubator-echarts-2.2.7/build/dist'
    }
});

// 使用
require(
    [
        'echarts',
        'echarts/chart/line',
        'echarts/chart/bar' // 使用柱状图就加载bar模块，按需加载
    ],
    function (ec) {
        var myChart = ec.init(document.getElementById('chartmain'));
        myChart.showLoading();
        var param = {
            id: document.getElementById('activity-id').value
        };
        $.ajax({
            url: "/activity/recordView",
            type: 'post',
            async: true,
            data: param,
            dataType: 'json',
            success: function (res) {
                myChart.hideLoading();
                var result = res.data;
                var option = {
                    title: {
                        text: '参与人数统计',
                        x: 'center'
                    },
                    tooltip: {
                        show: true,
                        trigger: 'item',
                        formatter: "{a} <br/>{b} : {c}人"
                    },
                    legend: {
                        x: 'left',
                        data: ['人数']
                    },
                    toolbox: {
                        show: true,
                        feature: {
                            dataView: {show: true, readOnly: false},
                            magicType: {
                                show: true,
                                type: ['bar', 'line'],
                                option: {
                                    funnel: {
                                        x: '25%',
                                        width: '50%',
                                        funnelAlign: 'left',
                                        max: 1548
                                    }
                                }
                            },
                            restore: {show: true},
                            saveAsImage: {show: true}
                        }
                    },
                    xAxis: [
                        {
                            type: 'category',
                            data: result.keys,
                            show: true
                        }
                    ],
                    yAxis: [
                        {
                            type: 'value'
                        }
                    ],
                    calculable: true,
                    series: [
                        {
                            name: "人数",
                            type: 'bar',
                            data: result.values
                        }
                    ]
                };
                // 为echarts对象加载数据
                myChart.setOption(option);
            }
        });
    }
);